package com.tangpian.sna.core.service;

import java.util.Date;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tangpian.sna.core.analysis.lda.LdaAnalyzer;
import com.tangpian.sna.core.analysis.polarity.PolarityAnalyzer;
import com.tangpian.sna.core.analysis.svm.SvmAnalyzer;
import com.tangpian.sna.core.dao.ItemDao;
import com.tangpian.sna.core.fetcher.WeiboFetcher;
import com.tangpian.sna.core.model.WeiboItem;

@Service
public class WeiboService {

	@Autowired
	private WeiboFetcher weiboFetcher;

	@Autowired
	private LdaAnalyzer<WeiboItem> ldaAnalyzer;

	@Autowired
	private SvmAnalyzer<WeiboItem> svmAnalyzer;

	@Autowired
	private PolarityAnalyzer<WeiboItem> polarityAnalyzer;

//	@Resource(name="itemRdbDao")
	@Resource(name="itemMongodbDao")
	private ItemDao<WeiboItem> itemDao;
	
	@PostConstruct
	public void init() {
		weiboFetcher.setMaxDays(30);
		weiboFetcher.setMaxPages(1000);
		weiboFetcher.setDate(new Date());
		weiboFetcher.setItemDao(itemDao);
		ldaAnalyzer.setTopicNumber(50);
	}

	@Test
	public void analysis() {
//		String[] movies = new String[] { "北京遇上西雅图", "厨子戏子痞子", "被解放的姜戈", "毒战",
//				"忠烈杨家将", "疯狂原始人", "钢铁侠3", "花漾", "星爸客", "致我们终将逝去的青春" };
//
//
//		for (String keyword : movies) {
			weiboFetcher.fetch("中国移动");

//			List<WeiboItem> items = itemDao.findByKeyword(keyword);
//
//			System.out.println(items.size());
//
//			ldaAnalyzer.analysis(items);
//			svmAnalyzer.analysis(items);
//			polarityAnalyzer.analysis(items);

		
	}

}
